package com.yunwushanhe.student.controller;

import com.yunwushanhe.student.bean.req.PageReq;
import com.yunwushanhe.student.bean.ret.Result;
import com.yunwushanhe.student.bean.req.ScoreAddReq;
import com.yunwushanhe.student.bean.req.ScoreUpdateReq;
import com.yunwushanhe.student.bean.ret.ScoreAndStudentName;
import com.yunwushanhe.student.entity.Score;
import com.yunwushanhe.student.service.ScoreService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 这个类主要是指用户（）
 */
@RestController
@RequestMapping("/score")
public class ScoreController {

    @Resource
    private ScoreService scoreService;

    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated ScoreAddReq addReq){
        return scoreService.add(addReq);
    }

    @PostMapping("/selectPage")
    public Result<List<ScoreAndStudentName>> selectPage(@RequestBody PageReq pageReq){
        return scoreService.selectPage(pageReq);
    }

    @GetMapping("/deleteById")
    public Result<String> deleteById(Long id){
        if(id == null){
            return Result.fail("删除失败，控制器接收参数 id 不能为空！");
        }
        return scoreService.deleteById(id);
    }

    @GetMapping("/selectById")
    public Result<ScoreAndStudentName> selectById(Long id){ // 这里之所以要用 ScoreAndStudentName 这个类，与前端页面展示的数据有关
        if(id == null){
            return Result.fail("查询失败，控制器接收参数 id 不能为空！");
        }
        return scoreService.selectById(id);
    }

    @PostMapping("/updateById")
    public Result<String> updateById(@RequestBody @Validated ScoreUpdateReq updateReq){
        return scoreService.updateById(updateReq);
    }



}
